package com.briup.jz.service.impl;

import com.briup.jz.bean.Platform;
import com.briup.jz.bean.PlatformExample;
import com.briup.jz.dao.PlatformMapper;
import com.briup.jz.service.IPlatformService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class PlatfomImpl implements IPlatformService {
    @Resource
    private PlatformMapper platformMapper;
    @Override
    public List<Platform> query(Long id) {
        PlatformExample example =new PlatformExample();
        if (id!=null){
            example.createCriteria().andIdEqualTo(id);
        }
        return platformMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(Platform platform) throws CustomerException {
        //            判断用户是否输入id
        if (platform.getId()==null){
//没有输入则插入
            platformMapper.insert(platform);
        }else {
//            如果输入则为修改
            PlatformExample example=new PlatformExample();
//            查询改id的用户
            example.createCriteria().andIdEqualTo(platform.getId());
//            根据查询条件修改用户信息
            platformMapper.updateByExampleSelective(platform,example);
        }
    }

    @Override
    public void deleteById(Long id) throws CustomerException {
//        查找是否有该平台账户信息
        Platform platform=platformMapper.selectByPrimaryKey(id);
//        如果不存在
        if (platform==null){
            throw new CustomerException("没有这个平台账户信息");
        }
        platformMapper.deleteByPrimaryKey(id);
    }
}
